﻿using LChat.Data;
using LDisignPatern;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Llaans.Web.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        ChatDb chats = new ChatDb();
        [AllowAnonymous]
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }
        public ActionResult Create()
        {
            return View();
        }

        public ActionResult CreateChatChahel(ChanelsName chatNems)
        {
            var chatName = new ChanelsName
                {
                    ChatsName = chatNems.ChatsName,
                    CreationTime = DateTime.Now,

                };
            chats.ChanelsNems.Add(chatName);
            chats.SaveChanges();
            return Redirect("/");
        }
          [EditorBrowsable(EditorBrowsableState.Never)]
        public ActionResult CreateNewMassage(int chatNameId, string massage)
        {
            var chatName = chats.ChanelsNems.FirstOrDefault(r => r.Id == chatNameId);
            chats.ChatMessages.Add(
                new ChatMessage()
                {
                    CreationTime = DateTime.Now,
                    Message = massage,

                });
            chats.SaveChanges();
            return Redirect("/Chats/" + chatNameId);
        }
    }
}